package com.sky.service.impl;

import com.sky.dto.RecordVideoDto;
import com.sky.entity.RecordVideo;
import com.sky.exception.BaseException;
import com.sky.mapper.RecordMapper;
import com.sky.service.RecordVideoService;
import com.sky.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @ClassName: xiaoZhang
 * @Description:
 * @Author: Zhang
 * @CreateDate: 2025-05-14 16:03
 */
@Slf4j
@Service
public class RecordVideoServiceImpl implements RecordVideoService {
    @Autowired
    private RecordMapper recordMapper;

    public void saveRecordVideo(RecordVideoDto recordVideoDto) {
        String RecordId = recordVideoDto.getRecordId();
        String RecordData = recordVideoDto.getRecordData();
        if(StringUtil.isEmpty(RecordId)){
           throw new BaseException("recordId is not null");
        }
        if(StringUtil.isEmpty(RecordData)){
            throw new BaseException("recordData is not null");
        }
        // 创建记录实体
        RecordVideo recordVideo = new RecordVideo();

        recordVideo.setRecordData(RecordData);
        recordVideo.setRecordId(RecordId);
        recordVideo.setUpdateTime(LocalDateTime.now());
        recordVideo.setCreateTime(LocalDateTime.now());
        //插入一条记录到数据库
        recordMapper.recordVideoInsert(recordVideo);
    }
    @Override
    public RecordVideo queryRecordVideo(String recordId) {
        RecordVideo recordVideo = recordMapper.getByIdRecord(recordId);
        log.info("recordVideo:{}", recordVideo);
        return recordVideo;
    }
}
